//
// Simple passthrough vertex shader
//
attribute vec3 in_Position;                  // (x,y,z)
//attribute vec3 in_Normal;                  // (x,y,z)     unused in this shader.	
attribute vec4 in_Colour;                    // (r,g,b,a)
attribute vec2 in_TextureCoord;              // (u,v)

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main()
{
    vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
    
    v_vColour = in_Colour;
    v_vTexcoord = in_TextureCoord;
}

//######################_==_YOYO_SHADER_MARKER_==_######################@~//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform vec2 iResolution;
uniform float iTime;


void main() {
    vec2 uv = (v_vTexcoord.xy * iResolution.xy*2. - iResolution.xy) /iResolution.x/6.0;
    vec2 uv0 = uv;
    float finalColor = 0.0;
    
    for (int i = 0; i < 4; i++) {
        float dir = atan(uv.y, uv.x); // 使用安全阈值避免除零
        float A = 44.0096591700;
        float d = 0.0;
        
        if (iTime < A) {
            d = sin(length(uv*24.0)) / 1.5 * exp(-cos(dir*24.0));
        } else {
            d = (1.0-exp(-(iTime-A)*1.0)+sin(length(uv*24.0))*exp(-(iTime-A)*2.0)) / 1.5 * exp(-cos(dir*24.0));
        }
        
        float fi = float(i);
        float col = 0.5 + 0.5*cos( 6.28318*(length(uv0) + fi*0.4 - iTime*0.4 + 0.5));
        d = sin(d*8. - iTime)/8.;
        d = abs(d);
        d = max(d, 0.01); // 替代if判断保证最小值
        d = pow(0.01 / d, 1.2);
        finalColor += col*d;
    }
    
    finalColor = (finalColor > 0.75) ? 1.0 : 
                ((finalColor > 0.25) ? 0.5 : 0.0);
    finalColor /= 5.0;
    gl_FragColor = vec4(finalColor, finalColor, finalColor, 1.0);
}

